﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using System.Reflection;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

using System.IO;
using TVC.Layout;

namespace TVC.Modules.Com
{
    /// <summary>
    /// Summary description for CustomWindowPanelControl.
    /// </summary>

    [Serializable()]
    public class DA : ModuleParent, IHostedApplication
    {
        private TabControl tabControl1;
        private TabPage tbList;
        private TabPage tbDetail;
        private Label label2;
        private TextBox txtNAME;
        private TextBox txtDAG_ID;
        private Label label1;
        private Label label7;
        private TextBox txtEI;
        private DataGridView dgvList;
        private Label label3;
        private Label label5;
        private Label label4;
        private Button btnRemove;
        private Button btnClear;
        private Button btnAdd;
        private Button btnFill;
        private ListBox libDataAccessGroup;
        private ListBox libGroup;
        private DataGridViewTextBoxColumn colDAG_ID;
        private DataGridViewTextBoxColumn colNAME;
        private DataGridViewTextBoxColumn colEI;
        private BindingSource bisDA;
        private IContainer components;
        private ContextMenu ctmGrid;
        private MenuItem menuItem1;
        private MenuItem mnuSaveLayout;
        private MenuItem mnuResetLayout;
        private MenuItem mnuShowFilter;
        private string strAction;
        public DA()
        {
            // This call is required by the WebGUI Form Designer.
            InitializeComponent();
            _dgvList = dgvList;
            _tabControl = tabControl1;
            _strType = "DA";
        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        int idAllowEditLanguage = 1;
        int idAddNew = 45;
        int idEdit = 46;
        int idDelete = 47;
        int idTransferIn = 48;
        int idTransferOut = 49;
        int idPrint = 50;
        int idToExcel = 261;


        protected override void LoadLanguage(string language)
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            clsConfigurarion.GetLabel(this.ToString(), y, language);
                    }
                }
            }
            //clsConfigurarion.GetLabel(this.ToString(), lbUserID, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblDescription, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblLanguage, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblDbDefault, language);
            //clsConfigurarion.GetLabel(this.ToString(), lklRole, language);
            //clsConfigurarion.GetLabel(this.ToString(), lklEmp, language);

            if (this.Parent is HeaderedPanel)
            {
                HeaderedPanel pln = this.Parent as HeaderedPanel;
                _title = clsConfigurarion.GetLabel(this.ToString(), "", null, language);
            }
        }
        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            if (IsPermis(idAddNew)) objElements.Add(new HostedToolBarButton("Add New", new IconResourceHandle("Add.png"), "C"));
            if (IsPermis(idEdit)) objElements.Add(new HostedToolBarButton("Edit", new IconResourceHandle("Edit.png"), "A"));
            if (IsPermis(idAddNew) && IsPermis(idEdit)) objElements.Add(new HostedToolBarButton("Save", new IconResourceHandle("Save.png"), "S", false));
            if (IsPermis(idAddNew)) objElements.Add(new HostedToolBarButton("Copy", new IconResourceHandle("Copy.png"), "O"));
            objElements.Add(new HostedToolBarButton("Skip", "Skip", new IconResourceHandle("Reject.png"), "K", false));
            if (IsPermis(idDelete)) objElements.Add(new HostedToolBarButton("Delete", new IconResourceHandle("Delete.png"), "X"));

            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idTransferIn))
                objElements.Add(new HostedToolBarButton("Import", new IconResourceHandle("Down.png"), "TI"));
            if (IsPermis(idPrint)) objElements.Add(new HostedToolBarButton("To XML", "To XML", new IconResourceHandle("Up.png"), "TO"));
            if (IsPermis(idToExcel)) objElements.Add(new HostedToolBarButton("To Excel", "To Excel", new IconResourceHandle("Excel.png"), "EXCEL"));

            objElements.Add(new HostedToolBarSeperator());
            objElements.Add(new HostedToolBarButton("Refresh", new IconResourceHandle("Refresh.png"), "R"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }
        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                sErr = "";
                strAction = (string)objButton.Tag;
                BUS.LIST_DAOGControl daogCtr = new BUS.LIST_DAOGControl();
                BUS.LIST_DAControl ctr = new BUS.LIST_DAControl();
                switch (strAction)
                {
                    case "C":
                        AddNew(txtDAG_ID);
                        break;
                    case "A":
                        editRecord(txtDAG_ID);
                        break;
                    case "S":
                        saveRecord(txtDAG_ID);
                        break;
                    case "K":
                        skip();
                        break;
                    case "O":
                        copy(txtDAG_ID);

                        break;
                    case "X":
                        delete(txtDAG_ID);

                        break;
                    case "TI": //trans in
                        importData();
                        break;
                    case "TO": //Tran out
                        export2Xml();
                        break;
                    case "EXCEL": //Tran out
                        export2Excel();
                        break;
                    case "R":
                        reloadList();
                        break;
                    case "P":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.LIST_DAInfo info = new DTO.LIST_DAInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            DataTable dt = DTO.LIST_DAInfo.ToDataTable();
                            dt.Rows.Add(info.ToDataRow(dt));
                            DataSet ds = new DataSet();
                            ds.Tables.Add(dt);
                            MainForm main = GetMainForm();
                            if (main != null)
                                main.PrintDataSet(ds, _strType);
                        }
                        break;
                }
                if (sErr == "") ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }

        #region Component Designer generated code
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.tabControl1 = new Gizmox.WebGUI.Forms.TabControl();
            this.tbList = new Gizmox.WebGUI.Forms.TabPage();
            this.dgvList = new Gizmox.WebGUI.Forms.DataGridView();
            this.colDAG_ID = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.colNAME = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.colEI = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.ctmGrid = new Gizmox.WebGUI.Forms.ContextMenu();
            this.menuItem1 = new Gizmox.WebGUI.Forms.MenuItem();
            this.mnuSaveLayout = new Gizmox.WebGUI.Forms.MenuItem();
            this.mnuResetLayout = new Gizmox.WebGUI.Forms.MenuItem();
            this.mnuShowFilter = new Gizmox.WebGUI.Forms.MenuItem();
            this.bisDA = new Gizmox.WebGUI.Forms.BindingSource(this.components);
            this.tbDetail = new Gizmox.WebGUI.Forms.TabPage();
            this.label5 = new Gizmox.WebGUI.Forms.Label();
            this.label4 = new Gizmox.WebGUI.Forms.Label();
            this.btnRemove = new Gizmox.WebGUI.Forms.Button();
            this.btnClear = new Gizmox.WebGUI.Forms.Button();
            this.btnAdd = new Gizmox.WebGUI.Forms.Button();
            this.btnFill = new Gizmox.WebGUI.Forms.Button();
            this.libDataAccessGroup = new Gizmox.WebGUI.Forms.ListBox();
            this.libGroup = new Gizmox.WebGUI.Forms.ListBox();
            this.label3 = new Gizmox.WebGUI.Forms.Label();
            this.txtEI = new Gizmox.WebGUI.Forms.TextBox();
            this.label7 = new Gizmox.WebGUI.Forms.Label();
            this.label2 = new Gizmox.WebGUI.Forms.Label();
            this.txtNAME = new Gizmox.WebGUI.Forms.TextBox();
            this.txtDAG_ID = new Gizmox.WebGUI.Forms.TextBox();
            this.label1 = new Gizmox.WebGUI.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).BeginInit();
            this.tabControl1.SuspendLayout();
            this.tbList.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisDA)).BeginInit();
            this.tbDetail.SuspendLayout();
            this.SuspendLayout();
            // 
            // errProvider
            // 
            this.errProvider.BlinkStyle = Gizmox.WebGUI.Forms.ErrorBlinkStyle.BlinkIfDifferentError;
            // 
            // warnProvider
            // 
            this.warnProvider.BlinkStyle = Gizmox.WebGUI.Forms.ErrorBlinkStyle.BlinkIfDifferentError;
            // 
            // tabControl1
            // 
            this.tabControl1.Alignment = Gizmox.WebGUI.Forms.TabAlignment.Bottom;
            this.tabControl1.Appearance = Gizmox.WebGUI.Forms.TabAppearance.Workspace;
            this.tabControl1.Controls.Add(this.tbList);
            this.tabControl1.Controls.Add(this.tbDetail);
            this.tabControl1.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(3, 3);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(601, 442);
            this.tabControl1.TabIndex = 0;
            // 
            // tbList
            // 
            this.tbList.Controls.Add(this.dgvList);
            this.tbList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbList.Location = new System.Drawing.Point(4, 22);
            this.tbList.Name = "tbList";
            this.tbList.Size = new System.Drawing.Size(593, 416);
            this.tbList.TabIndex = 0;
            this.tbList.Text = "List";
            // 
            // dgvList
            // 
            this.dgvList.AllowDrag = false;
            this.dgvList.AllowUserToAddRows = false;
            this.dgvList.AutoGenerateColumns = false;
            this.dgvList.BackgroundColor = System.Drawing.Color.White;
            this.dgvList.ColumnHeadersHeightSizeMode = Gizmox.WebGUI.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvList.Columns.AddRange(new Gizmox.WebGUI.Forms.DataGridViewColumn[] {
            this.colDAG_ID,
            this.colNAME,
            this.colEI});
            this.dgvList.ContextMenu = this.ctmGrid;
            this.dgvList.DataSource = this.bisDA;
            this.dgvList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.dgvList.Location = new System.Drawing.Point(0, 0);
            this.dgvList.Name = "dgvList";
            this.dgvList.RowHeadersWidth = 25;
            this.dgvList.RowTemplate.DefaultCellStyle.FormatProvider = new System.Globalization.CultureInfo("en-US");
            this.dgvList.ShowFilterRow = true;
            this.dgvList.Size = new System.Drawing.Size(593, 416);
            this.dgvList.TabIndex = 0;
            // 
            // colDAG_ID
            // 
            this.colDAG_ID.DataPropertyName = "DAG_ID";
            this.colDAG_ID.HeaderText = "Code";
            this.colDAG_ID.Name = "colDAG_ID";
            // 
            // colNAME
            // 
            this.colNAME.AutoSizeMode = Gizmox.WebGUI.Forms.DataGridViewAutoSizeColumnMode.Fill;
            this.colNAME.DataPropertyName = "NAME";
            this.colNAME.HeaderText = "Description";
            this.colNAME.Name = "colNAME";
            // 
            // colEI
            // 
            this.colEI.DataPropertyName = "EI";
            this.colEI.HeaderText = "EI";
            this.colEI.Name = "colEI";
            // 
            // ctmGrid
            // 
            this.ctmGrid.MenuItems.AddRange(new Gizmox.WebGUI.Forms.MenuItem[] {
            this.menuItem1,
            this.mnuShowFilter});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.MenuItems.AddRange(new Gizmox.WebGUI.Forms.MenuItem[] {
            this.mnuSaveLayout,
            this.mnuResetLayout});
            this.menuItem1.Text = "Layout";
            // 
            // mnuSaveLayout
            // 
            this.mnuSaveLayout.Index = 0;
            this.mnuSaveLayout.Tag = "SAVE";
            this.mnuSaveLayout.Text = "Save Layout";
            // 
            // mnuResetLayout
            // 
            this.mnuResetLayout.Index = 1;
            this.mnuResetLayout.Tag = "RESET";
            this.mnuResetLayout.Text = "Reset Layout";
            // 
            // mnuShowFilter
            // 
            this.mnuShowFilter.Index = 1;
            this.mnuShowFilter.Tag = "FILTER";
            this.mnuShowFilter.Text = "Filter Records";
            // 
            // bisDA
            // 
            this.bisDA.DataSource = typeof(DTO.LIST_DAInfo);
            // 
            // tbDetail
            // 
            this.tbDetail.Controls.Add(this.label5);
            this.tbDetail.Controls.Add(this.label4);
            this.tbDetail.Controls.Add(this.btnRemove);
            this.tbDetail.Controls.Add(this.btnClear);
            this.tbDetail.Controls.Add(this.btnAdd);
            this.tbDetail.Controls.Add(this.btnFill);
            this.tbDetail.Controls.Add(this.libDataAccessGroup);
            this.tbDetail.Controls.Add(this.libGroup);
            this.tbDetail.Controls.Add(this.label3);
            this.tbDetail.Controls.Add(this.txtEI);
            this.tbDetail.Controls.Add(this.label7);
            this.tbDetail.Controls.Add(this.label2);
            this.tbDetail.Controls.Add(this.txtNAME);
            this.tbDetail.Controls.Add(this.txtDAG_ID);
            this.tbDetail.Controls.Add(this.label1);
            this.tbDetail.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbDetail.Location = new System.Drawing.Point(0, 0);
            this.tbDetail.Name = "tbDetail";
            this.tbDetail.Size = new System.Drawing.Size(593, 416);
            this.tbDetail.TabIndex = 1;
            this.tbDetail.Text = "Detail";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(262, 97);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(56, 13);
            this.label5.TabIndex = 0;
            this.label5.Text = "Group in Data Access";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(16, 97);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(56, 13);
            this.label4.TabIndex = 0;
            this.label4.Text = "Group";
            // 
            // btnRemove
            // 
            this.btnRemove.Location = new System.Drawing.Point(199, 215);
            this.btnRemove.Name = "btnRemove";
            this.btnRemove.Size = new System.Drawing.Size(56, 23);
            this.btnRemove.TabIndex = 7;
            this.btnRemove.Text = "<";
            this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
            // 
            // btnClear
            // 
            this.btnClear.Location = new System.Drawing.Point(199, 255);
            this.btnClear.Name = "btnClear";
            this.btnClear.Size = new System.Drawing.Size(56, 23);
            this.btnClear.TabIndex = 8;
            this.btnClear.Text = "<<";
            this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
            // 
            // btnAdd
            // 
            this.btnAdd.Location = new System.Drawing.Point(199, 175);
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(56, 23);
            this.btnAdd.TabIndex = 6;
            this.btnAdd.Text = ">";
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            // 
            // btnFill
            // 
            this.btnFill.Location = new System.Drawing.Point(199, 135);
            this.btnFill.Name = "btnFill";
            this.btnFill.Size = new System.Drawing.Size(56, 23);
            this.btnFill.TabIndex = 5;
            this.btnFill.Text = ">>";
            this.btnFill.Click += new System.EventHandler(this.btnFill_Click);
            // 
            // libDataAccessGroup
            // 
            this.libDataAccessGroup.Location = new System.Drawing.Point(265, 110);
            this.libDataAccessGroup.Name = "libDataAccessGroup";
            this.libDataAccessGroup.SelectionMode = Gizmox.WebGUI.Forms.SelectionMode.One;
            this.libDataAccessGroup.Size = new System.Drawing.Size(169, 199);
            this.libDataAccessGroup.TabIndex = 4;
            // 
            // libGroup
            // 
            this.libGroup.Location = new System.Drawing.Point(19, 110);
            this.libGroup.Name = "libGroup";
            this.libGroup.SelectionMode = Gizmox.WebGUI.Forms.SelectionMode.One;
            this.libGroup.Size = new System.Drawing.Size(169, 199);
            this.libGroup.TabIndex = 3;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(99, 67);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(56, 13);
            this.label3.TabIndex = 0;
            this.label3.Text = "I/E";
            // 
            // txtEI
            // 
            this.txtEI.AllowDrag = false;
            this.txtEI.Location = new System.Drawing.Point(119, 64);
            this.txtEI.MaxLength = 1;
            this.txtEI.Name = "txtEI";
            this.txtEI.Size = new System.Drawing.Size(76, 20);
            this.txtEI.TabIndex = 2;
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(16, 67);
            this.label7.Name = "label6";
            this.label7.Size = new System.Drawing.Size(56, 13);
            this.label7.TabIndex = 0;
            this.label7.Text = "Include/Exclude";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(16, 41);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "Description";
            // 
            // txtNAME
            // 
            this.txtNAME.AllowDrag = false;
            this.txtNAME.Location = new System.Drawing.Point(119, 38);
            this.txtNAME.MaxLength = 100;
            this.txtNAME.Name = "txtNAME";
            this.txtNAME.Size = new System.Drawing.Size(329, 20);
            this.txtNAME.TabIndex = 1;
            // 
            // txtDAG_ID
            // 
            this.txtDAG_ID.AllowDrag = false;
            this.txtDAG_ID.Location = new System.Drawing.Point(119, 12);
            this.txtDAG_ID.MaxLength = 15;
            this.txtDAG_ID.Name = "txtDAG_ID";
            this.txtDAG_ID.Size = new System.Drawing.Size(100, 20);
            this.txtDAG_ID.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(16, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Code";
            // 
            // DA
            // 
            this.Controls.Add(this.tabControl1);
            this.DockPadding.All = 3;
            this.Location = new System.Drawing.Point(0, -10);
            this.Padding = new Gizmox.WebGUI.Forms.Padding(3);
            this.Size = new System.Drawing.Size(607, 448);
            this.Load += new System.EventHandler(this.DA_Load);
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).EndInit();
            this.tabControl1.ResumeLayout(false);
            this.tbList.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisDA)).EndInit();
            this.tbDetail.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion


        #region IHostedApplication Members

        public void InitializeApplication()
        {

        }
        public void SetObject(object obj)
        {

        }


        private DTO.LIST_DAInfo GetData()
        {
            return new DTO.LIST_DAInfo(txtDAG_ID.Text
                , txtNAME.Text
                , txtEI.Text == "E" ? "E" : "I"
                );

        }

        private void SetData(DTO.LIST_DAInfo info)
        {
            txtDAG_ID.Text = info.DAG_ID;
            txtNAME.Text = info.NAME;
            txtEI.Text = info.EI;
            SetGroup(info);
        }

        private string[] GetGroup()
        {
            if (libDataAccessGroup.Items.Count == 0)
                return null;
            string[] role = new string[libDataAccessGroup.Items.Count];
            for (int i = 0; i < libDataAccessGroup.Items.Count; i++)
            {
                role[i] = libDataAccessGroup.Items[i].ToString();
            }
            return role;
        }
        private void SetGroup(DTO.LIST_DAInfo info)
        {
            BUS.LIST_DAOGControl ctr = new BUS.LIST_DAOGControl();
            DataTable dt = ctr.GetAll(info.DAG_ID, ref sErr);
            foreach (DataRow row in dt.Rows)
            {
                libGroup.Items.Remove(row["ROLE_ID"].ToString());
                if (!libDataAccessGroup.Items.Contains(row["ROLE_ID"].ToString()))
                    libDataAccessGroup.Items.Add(row["ROLE_ID"].ToString());
            }
        }
        private void ClearGroup()
        {
            if (!GetMainForm().IsContainsTables("POG"))
                GetMainForm().LoadDataTable("POG");
            libDataAccessGroup.Items.Clear();
            foreach (DataRow row in GetMainForm().GetTable("POG").Rows)
            {
                if (!libGroup.Items.Contains(row["ROLE_ID"].ToString()))
                    libGroup.Items.Add(row["ROLE_ID"].ToString());
            }
        }

        #endregion

        #region .::| Override Functions |::.
        protected override ModuleParent.ErrorStatus validateForm(ref string sErr)
        {
            ErrorStatus result = ErrorStatus.SUCCESS;
            sErr = "";

            if (txtDAG_ID.Text.Trim() == "")
            {
                sErr = "Could not save blank, please check!";
                errProvider.SetError(txtDAG_ID, sErr);
                strAction = _processStatus;
                sErr += "\n";
                

            }
            else errProvider.SetError(txtDAG_ID, "");

            if (!(txtEI.Text == "E" || txtEI.Text == "I"))
            {
                sErr = "Must be I or E!";
                errProvider.SetError(txtEI, sErr);
                strAction = _processStatus;
                sErr += "\n";
               
            }
            else errProvider.SetError(txtEI, "");

            if (GetGroup() == null)
            {
                sErr = "Please add group!";
                errProvider.SetError(libDataAccessGroup, sErr);
                strAction = _processStatus;
                sErr += "\n";
                
            }
            else errProvider.SetError(libDataAccessGroup, "");

            if (sErr != "") result = ErrorStatus.ERROR;
            return result;
        }
        protected override bool checkExists()
        {
            BUS.LIST_DAControl ctr = new BUS.LIST_DAControl();
            return ctr.IsExist(txtDAG_ID.Text);

        }
        protected override void reloadList()
        {
            GetMainForm().LoadDataTable(_strType);
            bisDA.DataSource = GetMainForm().GetTable(_strType);
        }

        protected override string addRecord(bool isDraft = false)
        {
            string sErr = "";
            BUS.LIST_DAControl ctr = new BUS.LIST_DAControl();
            BUS.LIST_DAOGControl daogCtr = new BUS.LIST_DAOGControl();
            object trans = ctr.BeginTransaction(ref sErr);
            if (sErr == "") daogCtr.SetTransaction(trans);

            DTO.LIST_DAInfo info = GetData();
            if (sErr == "") ctr.Add(info, ref sErr);

            string[] arrrole = GetGroup();

            if (sErr == "") sErr = daogCtr.Deletes(info.DAG_ID);

            if (sErr == "")
            {
                foreach (string role in arrrole)
                {
                    DTO.LIST_DAOGInfo daoginf = new DTO.LIST_DAOGInfo(info.DAG_ID, role);
                    sErr = daogCtr.InsertUpdate(daoginf);
                    if (sErr != "") break;
                }
            }

            if (sErr == "") ctr.CommitTransaction(ref sErr);
            else ctr.RollbackTransaction(ref sErr);

            return sErr;
        }
        protected override string updateRecord(bool isDraft = false)
        {
            string sErr = "";
            BUS.LIST_DAControl ctr = new BUS.LIST_DAControl();
            BUS.LIST_DAOGControl daogCtr = new BUS.LIST_DAOGControl();
            object trans = ctr.BeginTransaction(ref sErr);

            if (sErr == "") daogCtr.SetTransaction(trans); daogCtr.SetTransaction(trans);

            DTO.LIST_DAInfo info = GetData();
            if (sErr == "") sErr = ctr.Update(info);

            string[] arrrole = GetGroup();

            if (sErr == "") sErr = daogCtr.Deletes(info.DAG_ID);

            if (sErr == "")
            {
                foreach (string role in arrrole)
                {
                    DTO.LIST_DAOGInfo daoginf = new DTO.LIST_DAOGInfo(info.DAG_ID, role);
                    sErr = daogCtr.InsertUpdate(daoginf);
                    if (sErr != "") break;
                }
            }

            if (sErr == "") ctr.CommitTransaction(ref sErr);
            else ctr.RollbackTransaction(ref sErr);

            return sErr;


        }
        protected override string delRecord()
        {
            string sErr = "";
            BUS.LIST_DAControl ctr = new BUS.LIST_DAControl();
            BUS.LIST_DAOGControl ctrdet = new BUS.LIST_DAOGControl();
            object trans = ctr.BeginTransaction(ref sErr);
            if (sErr == "") ctrdet.SetTransaction(trans);

            if (sErr == "") sErr = ctrdet.Deletes(txtDAG_ID.Text);
            if (sErr == "") sErr = ctr.Delete(txtDAG_ID.Text);

            if (sErr == "") ctr.CommitTransaction(ref sErr);
            else ctr.RollbackTransaction(ref sErr);

            return sErr;
        }
        protected override void refreshForm(string val)
        {
            txtDAG_ID.Text = val;
            txtNAME.Text = val;
            txtEI.Text = val;
            ClearGroup();

        }
        protected override void enableForm(bool val)
        {
            txtDAG_ID.Enabled = val;
            txtNAME.Enabled = val;
            txtEI.Enabled = val;
            libGroup.Enabled = val;
            libDataAccessGroup.Enabled = val;
            btnAdd.Enabled = val;
            btnClear.Enabled = val;
            btnFill.Enabled = val;
            btnRemove.Enabled = val;
        }

        protected override void loadRecord(object o)
        {
            if (o is DataRowView)
            {
                ClearGroup();
                DTO.LIST_DAInfo inf = new DTO.LIST_DAInfo((DataRowView)o);
                SetData(inf);
            }

        }

        #endregion
        private void DA_Load(object sender, EventArgs e)
        {
            enableForm(false);
            refreshForm("");
            if (idAllowEditLanguage >= GetMainForm().Permission.Length || GetMainForm().Permission[idAllowEditLanguage] == 'Y')
                AllowEditLanguage();
        }

        private void btnFill_Click(object sender, EventArgs e)
        {
            if (libGroup.Items.Count > 0)
                for (int i = libGroup.Items.Count - 1; i >= 0; i--)
                {
                    string obj = libGroup.Items[i].ToString();
                    libGroup.Items.Remove(obj);
                    libDataAccessGroup.Items.Add(obj);
                }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (libGroup.SelectedItem != null)
            {
                string obj = libGroup.SelectedItem.ToString();
                libDataAccessGroup.Items.Add(obj);
                libGroup.Items.Remove(obj);

            }
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (libDataAccessGroup.SelectedItem != null)
            {
                string obj = libDataAccessGroup.SelectedItem.ToString();
                libGroup.Items.Add(obj);
                libDataAccessGroup.Items.Remove(obj);

            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            if (libDataAccessGroup.Items.Count > 0)
                for (int i = libDataAccessGroup.Items.Count - 1; i >= 0; i--)
                {
                    string obj = libDataAccessGroup.Items[i].ToString();
                    libDataAccessGroup.Items.Remove(obj);
                    libGroup.Items.Add(obj);
                }
        }

    }
}
